<template>
  <a-card :bordered="false">
    <!-- 抽屉  title:抽屉标题 width:宽度  onClose:抽屉关闭事件  visible:是否显示-->
    <a-drawer title="滤芯列表" :width="screenWidth" @close="onClose" :visible="visible">
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding: '10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }"
      >
        <div class="table-page-search-wrapper">
          <a-row>
            <a-col :md="2" :sm="24">
              <a-button style="margin-bottom: 10px" type="primary" @click="handleAdd" v-if="send">新增</a-button>
            </a-col>
          </a-row>
        </div>
        <div>
          <a-table
            ref="table"
            rowKey="id"
            size="middle"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange"
            :rowClassName="getRowClassname"
          >
            <span slot="action" slot-scope="text, record">
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
          </a-table>
        </div>
      </div>
      <relationship-modal ref="modalForm" @ok="modalFormOk"></relationship-modal>
    </a-drawer>
    <!-- 字典数据 -->
  </a-card>
</template>

<script>
import pick from 'lodash.pick'
import { filterObj } from '@/utils/util'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import RelationshipModal from './modules/RelationshipModal'
import { Commodity, CommodityType } from '@/api/params'
export default {
  name: 'CommodityTypeltemList',
  mixins: [JeecgListMixin],
  components: { RelationshipModal },
  data() {
    return {
      columns: [
        {
          title: '滤芯名称',
          align: 'center',
          dataIndex: 'filterelementName',
        },
        {
          title: '可用天数',
          align: 'center',
          dataIndex: 'validity',
        },
        {
          title: '最低提醒天数',
          align: 'center',
          dataIndex: 'replacementdays',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      //商品类型Id
      typeId: '',
      queryParam: {
        typeId: '',
      },
      title: '操作',
      visible: false,
      screenWidth: 800,
      model: {},
      status: 1,
      labelCol: {
        xs: { span: 5 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 12 },
      },
      //控制不同的父组件进来是否显示新增或删除按钮
      send: true,
      url: {
        list: '/commodity/relationship/list',
        delete: '/commodity/relationship/del',
      },
    }
  },
  created() {
    // 当页面初始化时,根据屏幕大小来给抽屉设置宽度
    this.resetScreenSize()
  },
  methods: {
    //重写了jeecgListboot
    getQueryParams() {
      //update--begin--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      this.ipagination.total = 0
      //update--end--autor:wangshuai-----date:20191204------for：清空总条数 teambition JT-113------
      var param = Object.assign({}, this.queryParam)
      param.typeId = this.typeId
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
        param['superQueryMatchType'] = this.superQueryMatchType
      }
      return filterObj(param)
    },
    handleAdd() {
      this.$refs.modalForm.add(this.typeId)
    },
    showDrawer(id, type) {
      if (type == Commodity) {
        this.send = false
        this.columns = [
          {
            title: '滤芯名称',
            align: 'center',
            dataIndex: 'filterelementName',
          },
          {
            title: '可用天数',
            align: 'center',
            dataIndex: 'validity',
          },
          {
            title: '最低提醒天数',
            align: 'center',
            dataIndex: 'replacementdays',
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align: 'center',
          //   scopedSlots: { customRender: 'action' },
          // },
        ]
      } else if (type == CommodityType) {
        this.send = true
      }
      this.typeId = id
      //抽屉显示
      this.visible = true
      this.loadData()
    },
    onClose() {
      this.visible = false
      //查询结果清空
      this.dataSource = []
    },
    // 抽屉的宽度随着屏幕大小来改变
    resetScreenSize() {
      let screenWidth = document.body.clientWidth
      if (screenWidth < 600) {
        this.screenWidth = screenWidth
      } else {
        this.screenWidth = 600
      }
    },
    //update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
    //增加样式方法返回值
    getRowClassname(record) {
      if (record.status == 0) {
        return 'data-rule-invalid'
      }
    },
    //update--end--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
  },
}
</script>
<style lang="less" scoped>
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
/deep/ .data-rule-invalid {
  background: #f4f4f4;
  color: #bababa;
}
//update--begin--autor:wangshuai-----date:20191204------for：系统管理 数据字典禁用和正常区别开，添加背景颜色 teambition JT-22------
</style>